<?php
declare (strict_types=1);

namespace app\listener\template;

use app\event\TemplateEditSuccess as TemplateEditSuccessEvent;
use think\facade\Cache;
use app\model\Template;


class TemplateEditSuccess
{
    public $template;

    /**
     * 事件监听处理
     * @param TemplateEditSuccessEvent $template
     * @return mixed
     */
    public function handle(TemplateEditSuccessEvent $template)
    {
        /**
         * @var Template
         */
        $template = $template->template;
        if (!$template || $template->status != Template::STATUS_ACTIVE) {
            return;
        }
        $cache_key = 'JumpTypeMap_getJumpTypeList_template_serv_type_'.$template->pre_url;
        cache($cache_key, NULL);
        $template_serv_type = (new Template())->getServType($template->pre_url);
        Cache::set($cache_key, $template_serv_type, 4*3600);
    }
}
